﻿<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
  
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Services | EduCATS Xamarin Documentation </title>
    <meta name="viewport" content="width=device-width">
    <meta name="title" content="Services | EduCATS Xamarin Documentation ">
    <meta name="generator" content="docfx 2.51.0.0">
    
    <link rel="shortcut icon" href="../favicon.ico">
    <link rel="stylesheet" href="../styles/docfx.vendor.css">
    <link rel="stylesheet" href="../styles/docfx.css">
    <link rel="stylesheet" href="../styles/main.css">
    <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> 
    <meta property="docfx:navrel" content="../toc">
    <meta property="docfx:tocrel" content="toc">
    
    
    <meta property="docfx:newtab" content="true">
  </head>  <body data-spy="scroll" data-target="#affix" data-offset="120">
    <div id="wrapper">
      <header>
        
        <nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>
              
              <a class="navbar-brand" href="../index.html">
                <img id="logo" class="svg" src="../logo.svg" alt="">
              </a>
            </div>
            <div class="collapse navbar-collapse" id="navbar">
              <form class="navbar-form navbar-right" role="search" id="search">
                <div class="form-group">
                  <input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
                </div>
              </form>
                
                <ul class="nav level1 navbar-nav">
                      <li>
                          <a href="../articles/project-structure.html" title="About project">About project</a>
                      </li>
                      <li>
                          <a href="../api/EduCATS.html" title="Code documentation">Code documentation</a>
                      </li>
                </ul>    </div>
          </div>
        </nav>
      </header>
      <div role="main" class="container body-content hide-when-search">
        <div class="sidenav hide-when-search">
          <a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
          <div class="sidetoggle collapse" id="sidetoggle">
            <div>
              <div class="sidefilter">
                <form class="toc-filter">
                  <span class="glyphicon glyphicon-filter filter-icon"></span>
                  <input type="text" id="toc_filter_input" placeholder="Enter here to filter..." onkeypress="if(event.keyCode==13) {return false;}">
                </form>
              </div>
              <div class="sidetoc">
                <div class="toc" id="toc">
                  
                  <ul class="nav level1">
                    <li class="">
                      <a href="project-structure.html" title="Project structure" class="">Project structure</a>
                    </li>
                    <li class="">
                      <a href="resources.html" title="Resources" class="">Resources</a>
                    </li>
                    <li class="active">
                      <a href="services.html" title="Services" class="active">Services</a>
                    </li>
                    <li class="">
                      <a href="continuous-integration.html" title="Continious integration" class="">Continious integration</a>
                    </li>
                  </ul>        </div>
              </div>
            </div>
          </div>
        </div>
        <div class="article row grid-right">
          <div class="col-md-10">
            <article class="content wrap" id="_content" data-uid="">
<h1 id="services">Services</h1>

<p>To add a new service follow the next steps:</p>
<ol>
<li>Add the link to API service to <code>EduCATS/Networking/Links.cs</code> file:</li>
</ol>
<pre><code class="lang-csharp">public static string GetRecomendations =&gt; $&quot;{Servers.Current}/Tests/GetRecomendations&quot;;
</code></pre>
<ol start="2">
<li>Add the app service method to <code>EduCATS/Networking/AppServices/AppServices.cs</code>:</li>
</ol>
<pre><code class="lang-csharp">public static async Task&lt;object&gt; GetRecommendations(int subjectId, int userId)
{
  return await AppServicesController.Request($&quot;{Links.GetRecomendations}?subjectId={subjectId}&amp;studentId={userId}&quot;);
}
</code></pre>
<p>2.1. If you need <code>POST</code> request you should create the model for body in <code>EduCATS/Networking/Models</code> and use it like:</p>
<pre><code class="lang-csharp">static string postRequest(string username)
{
  var usernameBody = new UsernameModel {
    Username = username
  };
  
  var body = JsonController.ConvertObjectToJson(userLogin);
  return await AppServicesController.Request(Links.PostRequest, body);
}
</code></pre>
<ol start="3">
<li>Add the service callback to <code>EduCATS/Data/DataAccessCallbacks.cs</code>:</li>
</ol>
<pre><code class="lang-csharp">static async Task&lt;object&gt; getRecommendationsCallback(int subjectId, int userId) =&gt; await AppServices.GetRecommendations(subjectId, userId);
</code></pre>
<ol start="4">
<li>Add the model for API result in <code>EduCATS/Data/Models/{API_name}.cs</code>:</li>
</ol>
<pre><code class="lang-csharp">public class RecommendationModel
{
  [JsonProperty(&quot;IsTest&quot;)]
  public bool IsTest { get; set; }

  [JsonProperty(&quot;Id&quot;)]
  public int Id { get; set; }

  [JsonProperty(&quot;Text&quot;)]
  public string Text { get; set; }
}
</code></pre>
<ol start="5">
<li>Specify caching key in <code>EduCATS/Constants/GlobalConsts.cs</code>:</li>
</ol>
<pre><code class="lang-csharp">public const string DataGetRecommendationsKey = &quot;GET_RECOMMENDATIONS_KEY&quot;;
</code></pre>
<ol start="6">
<li>Add the method to <code>EduCATS/Data/DataAccess.cs</code>:</li>
</ol>
<pre><code class="lang-csharp">public async static Task&lt;List&lt;RecommendationModel&gt;&gt; GetRecommendations(int subjectId, int userId)
{
  var dataAccess = new DataAccess&lt;RecommendationModel&gt;(
    &quot;recommendations_fetch_error&quot;, // localized error key
    getRecommendationsCallback(subjectId, userId), // callback specified in DataAccessCallbacks.cs
    $&quot;{GlobalConsts.DataGetRecommendationsKey}/{subjectId}/{userId}&quot;); // specified caching key; this parameter is optional - no caching will be provided if null
  return getDataObject(dataAccess, await dataAccess.GetList()) as List&lt;RecommendationModel&gt;;
}
</code></pre>
<ol start="7">
<li>Use it inside your ViewModel:</li>
</ol>
<pre><code class="lang-csharp">var recommendations = await DataAccess.GetRecommendations(CurrentSubject.Id, AppUserData.UserId);
</code></pre>
</article>
          </div>
          
          <div class="hidden-sm col-md-2" role="complementary">
            <div class="sideaffix">
              <nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
              <!-- <p><a class="back-to-top" href="#top">Back to top</a><p> -->
              </nav>
            </div>
          </div>
        </div>
      </div>
      
      <footer>
        <div class="grad-bottom"></div>
        <div class="footer">
          <div class="container">
            <span class="pull-right">
              <a href="#top">Back to top</a>
            </span>
            Copyright (C) EduCATS. Generated by DocFX.
            
          </div>
        </div>
      </footer>
    </div>
    
    <script type="text/javascript" src="../styles/docfx.vendor.js"></script>
    <script type="text/javascript" src="../styles/docfx.js"></script>
    <script type="text/javascript" src="../styles/main.js"></script>
  </body>
</html>
